<template>
	<div class="content">
		<h2><i class="iconfont icon-jinbi"></i>分配数据管理</h2>
		<div class="content-wrap">
			<!--搜索分类-->
			<div class="search">
				<div class="search__list">
					<div class="search__list--title">查询日期</div>
					<el-date-picker
							@change="handleSelectTimes"
						    v-model="times"
						    type="daterange"
						    range-separator="至"
						    start-placeholder="开始日期"
						    end-placeholder="结束日期"
						    size="mini">
				  	</el-date-picker>
				</div>
			</div>
			<!--商品展示表格-->
			<div class="content-table" v-loading="loading" >
				<el-table :data="data" strip size="mini">
					<el-table-column label="日期">
						<template slot-scope="scope">
							<span>{{scope.row.rcd_date}}</span>	
						</template>
					</el-table-column>
					<el-table-column label="当日发生点分">
						<template slot-scope="scope">
							<span>{{scope.row.gen_fen}}</span>	
						</template>
					</el-table-column>
					<el-table-column label="进入分配点分">
						<template slot-scope="scope">
							<span>{{scope.row.assign_fen}}</span>	
						</template>
					</el-table-column>
					<el-table-column label="未分配点分">
						<template slot-scope="scope">
							<span>{{scope.row.unassign_fen}}</span>	
						</template>
					</el-table-column>
					<el-table-column label="当日增权">
						<template slot-scope="scope">
							<span>{{scope.row.add_rights}}</span>	
						</template>
					</el-table-column>
					<el-table-column label="当日减权">
						<template slot-scope="scope">
							<span>{{scope.row.sub_rights}}</span>	
						</template>
					</el-table-column>
					<el-table-column label="当日发权">
						<template slot-scope="scope">
							<span>{{scope.row.give_rights}}</span>	
						</template>
					</el-table-column>
					<el-table-column label="预增权">
						<template slot-scope="scope">
							<span>{{scope.row.pre_add_rights}}</span>	
						</template>
					</el-table-column>
					<el-table-column label="应发单价">
						<template slot-scope="scope">
							<span>{{scope.row.should_price}}</span>	
						</template>
					</el-table-column>
					<el-table-column label="应发最高单价">
						<template slot-scope="scope">
							<span>{{scope.row.high_price}}</span>	
						</template>
					</el-table-column>
					<el-table-column label="当日发生点分">
						<template slot-scope="scope">
							<span>{{scope.row.all_price}}</span>	
						</template>
					</el-table-column>
					<el-table-column label="实发单价">
						<template slot-scope="scope">
							<span>{{scope.row.real_price}}</span>	
						</template>
					</el-table-column>
					<el-table-column label="预增权单价">
						<template slot-scope="scope">
							<span>{{scope.row.pre_price}}</span>	
						</template>
					</el-table-column>
					<el-table-column label="当日实发总数">
						<template slot-scope="scope">
							<span>{{scope.row.real_money}}</span>	
						</template>
					</el-table-column>
					<el-table-column label="累计实发总数">
						<template slot-scope="scope">
							<span>{{scope.row.total_real_money}}</span>	
						</template>
					</el-table-column>
					<el-table-column label="当日补贴">
						<template slot-scope="scope">
							<span>{{scope.row.allowance}}</span>	
						</template>
					</el-table-column>
					<el-table-column label="操作" align="center" width="100">
						<template slot-scope="scope" size="small">
							<el-button 
								size="mini"
								@click="dianyuanExchange(scope.row)">
								点元转化
							</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<el-pagination 
				@current-change="handleCurrentChange"
				background 
				layout="total, prev, pager, next, jumper"
				:total="totalNum" 
				class="fr"
				>
			</el-pagination>
		</div>
	</div>
</template>

<script>
	export default {
		created() {
			this.loadData();
		},
		components: {
		},
		data() {
			return {
				params: {
					page: 1,
					rows: 10,
					date1: "",
					date2: "",
					state: '',			//审核状态
				},
				showModel: false,			//显示申请详情
				data: null,					//提现数据			
				times: "",					//申请日期
				loading: true,				//加载小圈圈
				company_check_id: null,		//申请成为商户用户的id
				totalNum: 0					//返回数据总数，用于分页那里显示
			}
		},
		methods: {
			//翻页
			handleCurrentChange(pages) {
				this.params.page = pages;
				this.loadData();
			},
			//选择时间时候触发
			handleSelectTimes(val) {
				if (this.times) {
					this.params.date1 = this.times[0].getFullYear();
					var m1 = this.times[0].getMonth()+1;
					this.params.date1 += m1 > 9 ? m1 : '0' + m1;
					var d1 = this.times[0].getDate();
					this.params.date1 += d1 > 9 ? d1 : '0' + d1;
					this.params.date2 = this.times[1].getFullYear();
					m1 = this.times[1].getMonth()+1;
					this.params.date2 += m1 > 9 ? m1 : '0' + m1;
					d1 = this.times[1].getDate();
					this.params.date2 += d1 > 9 ? d1 : '0' + d1;
				}else {
					this.params.date1 = "";
					this.params.date2 = "";
				}
				this.loadData();
			},
			//获取商家详情
			loadData() {
				this.loading = true;
				var url = `${this.url}/caculate/caculate_get_data_list.action`;
				var params = this.params;
				this.$http.get(url,{ params }).then((res)=> {
					this.totalNum = res.data.result.total;
					this.loading = false;
					this.data = res.data.result.rows;
				});
			},
			// 点元转化
			dianyuanExchange(row) {
				var me = this;
				this.$prompt("请输入权单价", "权单价", {
					cancelButtonText: '取消',
					confirmButtonText: "确定",
				}).then(({ value })=> {
					if (value === null || value.replace(/\s/g, "") === "") {
						this.$message({
							type: "error",
							message: "请输入权单价"
						});
						return;
					}
					var patrn = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
					if (!patrn.exec(value) || parseFloat(value) <= 0) {
						this.$message({
							type: "error",
							message: "权单价必须为大于0的数字，最多两位小数"
						});
						return;
					}
					this.$confirm('确定对' + row.rcd_date + '进行点元转化？权单价：' + value + '元', {
	          			type: 'warning'
	        		}).then(() => {
	        			this.loading = true;
						var url = `${this.url}/caculate/caculate_exchange.action`;
						var params = {
							rcd_date: row.rcd_date,
							real_price: value,
						};
						this.$http.get(url,{ params }).then((res)=> {
							this.loading = false;
							if( res.data.success ) {
								this.$message({
									type: "success",
									message: '转化成功'
								});
							}else {
								this.$message({
									type: "error",
									message: res.data.result.errmsg
								});
							}
							me.loadData();
						});
					});
					
				}).catch(()=>{
					
				});
			}
		}

	}
</script>

<style scoped lang="scss">

</style>